/*
 * @Descripttion:
 * @version:
 * @Author: lwj
 * @Date: 2022-05-26 13:54:03
 * @LastEditors: yuanliutech@lwj
 * @LastEditTime: 2022-12-09 09:49:36
 */

//状态
const status = [{
        key: "0",
        value: "待隔离",
    },
    {
        key: "1",
        value: "隔离中",
    },
    {
        key: "1",
        value: "解除隔离",
    },
];
const transStatus = status.reduce((acc, cur) => {
    acc[cur.key] = cur.value;
    return acc;
}, {});

//激活
const isolateType = [{
        key: "0",
        value: "居家隔离",
    },
    {
        key: "1",
        value: "酒店隔离",
    },
    {
        key: "2",
        value: "其他隔离",
    },
];
const transActivation = isolateType.reduce((acc, cur) => {
    acc[cur.key] = cur.value;
    return acc;
}, {});


export default {
    methods: {
        onExport() {
            if (!this.optionArr.length)
                return this.$modal.notifyWarning('请勾选需要导出的隔离点');
            this.downloadLoading = true;
            import ("@/vendor/Export2Excel").then((excel) => {
                const tHeader = [
                    "安装点",
                    "隔离状态",
                    "隔离类型",
                    "所属建筑物",
                    "隔离开始时间",
                    "隔离天数",
                    "隔离人",
                ];
                const filterVal = [
                    "mountPoint",
                    "status",
                    "type",
                    "buildings",
                    "isolateStartTime",
                    "isolateTime",
                    "isolatePerson",
                ];
                const list = this.optionArr; //导出列表数据数组
                const data = this.formatJson(filterVal, list);

                excel.export_json_to_excel({
                    header: tHeader, //表头
                    data, //json数据
                    filename: "隔离管理", //导出文件名
                    autoWidth: true, //宽度是否自适应
                    bookType: "xlsx", //导出文件后缀名
                });
                this.downloadLoading = false;
                this.$modal.notifySuccess("导出成功，请在任务管理中查看");
            });
        },
        formatJson(filterVal, jsonData) {
            return jsonData.map((v) =>
                filterVal.map((j) => {
                    if (j === "status") {
                        return transStatus[v[j]];
                    }
                    if (j === "type") {
                        return transActivation[v[j]];
                    }
                    return v[j];
                })
            );
        },
    },
};